﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Web;

namespace PasswordManager
{
    public partial class Results : Form
    {
        public Form1 Parent { get; set; }
        public string ExitCode { get; set; }
        public Results()
        {
            InitializeComponent();
        }

        private void Results_Load(object sender, EventArgs e)
        {
            Size newSize = this.dataGridView1.GetPreferredSize(new Size(800, 600));
            //this.AutoSize = true;
            //this.dataGridView1.AutoSize = true;
            this.dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
            this.dataGridView1.AutoResizeColumns();
            this.dataGridView1.ScrollBars = ScrollBars.Both;
            this.dataGridView1.DefaultCellStyle.WrapMode = DataGridViewTriState.True;
            //this.Size = new Size(this.dataGridView1.Width, this.dataGridView1.Height);
            this.Size = newSize;
            this.dataGridView1.Size = newSize;
            //this.panel1.Size = new Size(500, 500);
            this.dataGridView1.Columns["CredentialId"].Visible = false;            
        }

      /*  void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                string copy = dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value as string;
                int index = e.RowIndex;
                Guid id = new Guid(dataGridView1.Rows[index].Cells[0].Value.ToString());
                if (copy == "#Delete#")
                {                    
                    Parent.m_adapter.DeleteCredentials(id);
                    this.ExitCode = "deleted";
                    this.Close();
                    return;
                }

                if (copy == "#Edit#")
                {
                    Edit ed = new Edit();
                    ed.toEdit = Parent.db.Credentials.Where(q => q.CredentialId == id).First();
                    ed.ShowDialog();
                    Parent.m_adapter.UpdateCredentials(ed.toEdit.Title, ed.toEdit.Username, ed.toEdit.Password, ed.toEdit.Additional, ed.toEdit.Description, ed.toEdit.CredentialId);
                    this.ExitCode = "edit";
                    this.Close();
                    return;
                }

                if (copy == "#Change Password#")
                {
                    string password = GeneratePassword();
                    Parent.m_adapter.UpdatePassword(password, id);
                    Clipboard.SetText(password);
                    this.ExitCode = "change password";
                    this.Close();
                    return;
                }

                if (!string.IsNullOrEmpty(copy))
                {
                    Clipboard.SetText(copy);
                }
            }
            catch { }
                                        
        }*/



        private void Results_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (string.IsNullOrEmpty(this.ExitCode))
            {
                this.ExitCode = "ok";
            }
        }



    }
}
